﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Salomon/MP/Base.Master" AutoEventWireup="true" CodeBehind="SeriesCreate.aspx.cs" Inherits="WebsiteAdmin.Salomon.ProInfo.SeriesCreate" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Head_Title" runat="server">新建系列 - 产品</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Head_Meta" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Head_Css" runat="server">

<style type="text/css">
    div.hide{ display:none;}

		#Dialog {
			position: absolute; 
			z-index: 1000; 
			display: none;
			width: 600px;
			background: #FFFFFF;
			border: 3px #999999 solid; 
		}
		#Dialog h6 {
			width: 580px;
			height: 20px;
			line-height: 20px;
			margin: 0;
			padding: 5px 10px; 
			background: #EFEFEF;
			text-align: right; 
			
		}
		#Dialog div.box {
			width: 600px;
			max-height:500px;
			overflow-y:scroll;
		}
		
		#Dialog div#DialogHtml
		{
		    width: 560px;
			padding: 10px; 
			color: #999;
		}
		
		#DialogHtml a {
			float: left;
			height: 20px; 
			line-height: 20px; 
			margin: 5px 15px 5px 0;
			white-space: nowrap;
		}
		
		#DialogHtml h4{ clear:both; background-color:#efefef; font-size:13px; margin-top:5px; display:block; height: 20px; 
			line-height: 20px; padding:5px;}
		
		#DialogHtml b{ float:left; clear:left; height: 20px; 
		    background-color:#efefef;
			line-height: 20px; 
			margin: 3px 15px 3px 0;
			padding:2px;
			white-space: nowrap;}
        
        #DialogHtml h4 a,#DialogHtml b a{ margin: 0;}	
		
	</style>
	
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="Head_Script" runat="server">
	<script type="text/javascript" src="/CKFinder/CKFinder.js"></script>
<script type="text/javascript" src="/Script/Mootools.Smoothbox.js"></script>
<script type="text/javascript" language="javascript">
    var MenuViewID = 2;

    Array.implement({
        getFirstRadio: function() {
            if (this.length == 0) {
                return null;
            }
            return this[0];
        }
    });
    window.addEvent('domready', function() {
        $('submitbtn').addEvent('click', function() {
            Submit();
        });

        $('ShowLink').addEvent('click', function() {
            BrowseServer('Images:/Series/', 'txbImgURL', 'ShowView');

        });
    });

    function SetFileField(fileUrl, data) {
        $(data["selectActionData"]).value = fileUrl;
        $(this).setProperty('src', fileUrl);
    }
    function BrowseServer(startupPath, functionData, element) {
        var finder = new CKFinder();
        finder.startupPath = startupPath;
        finder.selectActionData = functionData;
        finder.selectActionFunction = SetFileField.bind(element);
        finder.popup();
    }

    function ShowCat() {
        LightBox.show();
        $('DialogHtml').set('html', $('CatList').get('html'));
        ShowDialog();
    }

    function CloseDialog() {
        var obj = $('Dialog');
        if (obj.getStyle('display') != 'none') {
            $('DialogHtml').empty();
            obj.hide();
            LightBox.remove();
        }
    }

    function ShowDialog() {
        var scrollsize = $(window).getScroll();
        var allwindowSize = window.getSize();
        var dialogSize = $('Dialog').measure(function() {
            return this.getSize();
        });
        $('Dialog').setStyles({ 'left': scrollsize.x + (allwindowSize.x - dialogSize.x) / 2, 'top': scrollsize.y + (allwindowSize.y - dialogSize.y) / 2 }).show();
    }

    function CatSelect(e, t) {
        $('txbCatName').set('value', t);
        $('txbCatID').set('value', e);
        CloseDialog();
        LightBox.remove();
    }
    
    function Submit() {
        
        var txbCatID = $('txbCatID').get('value').trim().toInt();
        if (isNaN(txbCatID)) {
            alert('请选择分类');
            return false;
        }
        var txbSerTitle = $('txbSerTitle').get('value').trim();
        if (txbSerTitle.length == 0) {
            alert('标题错误');
            return false;
        }
        var txbDescription = $('txbDescription').get('value').trim();
        
        var txbImgURL = $('txbImgURL').get('value').trim();
        var txbSortOrder = $('txbSortOrder').get('value').trim().toInt();
        if (isNaN(txbSortOrder)) {
            alert('必须是整数');
            return false;
        }
        Insert(
        txbCatID,
        txbSerTitle,
        txbDescription,
        txbImgURL,
        txbSortOrder);
    }

    function Insert(txbCatID,
        txbSerTitle,
        txbDescription,
        txbImgURL,
        txbSortOrder) {

        new Request.JSON({
            method: 'post',
            url: 'Handler/SeriesInsert.ashx',
            data: {
                CatID: txbCatID,
                SerTitle: txbSerTitle,
                Description: txbDescription,
                ImgURL:txbImgURL,
                SortBy: txbSortOrder
            },
            noCache: true,
            onSuccess: function(data, text) {
                if (data.Done == 'Success') { 
                    
                    if(confirm('添加成功，返回列表？'))
                    {
                        document.location.href = '/Salomon/ProInfo/SeriesList.aspx';
                    };
                    LightBox.remove();
                }
                else
                {
                    alert('添加失败');
                    LightBox.remove();
                }
            },
            onFailure: function(xhr) {
                alert(xhr.statusText);
                LightBox.remove();
            }
        }).send();
    }
    
</script>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="Body_Top" runat="server">
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="Body_Content" runat="server">
    <div class="infobox">
        <h3>
        <span>新建系列</span>
			<a href="/Salomon/ProInfo/SeriesList.aspx" class="back action">返回系列列表</a>
        </h3>
        <div class="mt10">
        <form id="myForm" action="">
		    <table border="0" cellpadding="0" cellspacing="0" class="table_form">
		        <tr>
            		<td align="right" width="100"><span class="Need">所属分类：</span></td>
            		<td>
            			<input name="txbCatName" type="text" id="txbCatName" style="color:#666; background-color:#efefef; border:1px #ccc solid; " readonly="readonly" value="" /> <a href="javascript:void(0);" onclick="javascript:ShowCat();" >选择分类</a>
            			<input type="hidden" value="" id="txbCatID" name="txbCatID" />
            		</td>
				</tr>
		        <tr>
            		<td align="right" width="100"><span class="Need">系列名称：</span></td>
            		<td>
            			<input name="txbSerTitle" type="text" id="txbSerTitle" maxlength="20" size="20" />
            			<i>限10个汉字</i>
            		</td>
				</tr>
				<tr>
            		<td align="right" width="100"><span class="Need">简介：</span></td>
            		<td>
            			<textarea name="txbDescription" rows="3" cols="20" id="txbDescription"></textarea>
            		</td>
				</tr>
				<tr>
                    <td align="right" width="100">
                        图片：</td>
                    <td>
                           <input type="text" id="txbImgURL" name="txbImgURL" style="width:450px; color:#666; background-color:#efefef; border:1px #ccc solid;" readonly="readonly"  value="" /> <font color="red">*&nbsp;</font>
                           <a id="ShowLink" style="cursor:pointer;cursor:hand;border:solid 1px;padding:0 10px 0 10px;">浏览</a>
                    </td>
                </tr>
                <tr>
                    <td align="right" width="100">&nbsp;</td>
                    <td>
                        <div style=" width:300px; height:224px; overflow:hidden; border:1px #999 solid; background-color:#f8f8f8; clear:both;">
                           <img id="ShowView" alt="" src="/images/view.png" />
                        </div>
                        <i>图片尺寸 300 x 224。</i><br />
                        <i>如果图片不能完全填充，请重新选择图片。</i>
                    </td>
                </tr>
				<tr>
            		<td align="right" width="100"><span class="Need">显示排序：</span></td>
            		<td>
            			<input name="txbSortOrder" type="text" id="txbSortOrder" maxlength="2" size="5" value="50" />
            			<i>请输入数字</i>
            		</td>
				</tr>
		    </table>
		    <table border="0" cellpadding="0" cellspacing="0" class="table_form">
				<tr>
					<td width="100" height="40">&nbsp;</td>
					<td>
						<input id="submitbtn" type="button" value="提交" class="btn" />
						<input type="reset" value="重置" class="btn" />
					</td>
				</tr>
			</table>
		</form>
        </div>
    </div>
    
    <div id="Dialog">
		<h6>
			<a href="javascript:CloseDialog();">CLOSE</a>
		</h6>
		<div class="box">
		    <div id="DialogHtml"></div>
		</div>
	</div>
	<div class="hide" id="CatList">
	    <asp:Repeater ID="RP_Category" EnableViewState="False" runat="server" OnItemDataBound="RP_Category_ItemDataBound">
			<ItemTemplate>
			    <asp:Label ID="CatSelect" runat="server" />
			</ItemTemplate>
		</asp:Repeater>
	</div>
	
</asp:Content>
<asp:Content ID="Content7" ContentPlaceHolderID="Body_Foot" runat="server"  >
</asp:Content>